package org.linlinjava.litemall.db.service;

import com.github.yulichang.base.MPJBaseServiceImpl;
import org.linlinjava.litemall.db.dao.LitemallDistributionLogMapper;
import org.linlinjava.litemall.db.dao.LitemallRewardRuleConfigMapper;
import org.linlinjava.litemall.db.domain.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

/**
 * @program: litemall
 * @description: litemall_reward_rule
 * @author: chenyu
 * @create: 2022-03-15 10:59
 **/
@Service
public class LitemallDistributionLogService extends MPJBaseServiceImpl<LitemallDistributionLogMapper,LitemallDistributionLog> {
    @Resource
    private LitemallDistributionLogMapper litemallDistributionLogMapper;

    public void add(LitemallDistributionLog log) {
        litemallDistributionLogMapper.insert(log);
    }


    public List<LitemallDistributionLog> list(LitemallDistributionLogExample example) {
        return litemallDistributionLogMapper.selectByExample(example);
    }

    public void update(LitemallDistributionLog log) {
        litemallDistributionLogMapper.updateByPrimaryKeySelective(log);
    }

    public List<LitemallDistributionLog> findByStartAndEnd(LocalDate startDate, LocalDate endDate) {
        LitemallDistributionLogExample example = new LitemallDistributionLogExample();
        LitemallDistributionLogExample.Criteria criteria = example.createCriteria();
        criteria.andDeletedEqualTo(false);

        if (startDate != null) {
            criteria.andInviteDateGreaterThan(startDate);
        }

        if (endDate != null) {
            criteria.andInviteDateLessThan(endDate);
        }

        return litemallDistributionLogMapper.selectByExample(example);
    }

    public List<LitemallDistributionLog> logsByUserId(Integer userId) {
        LitemallDistributionLogExample example = new LitemallDistributionLogExample();
        LitemallDistributionLogExample.Criteria criteria = example.createCriteria();
        criteria.andDeletedEqualTo(false).andUserIdEqualTo(userId);

        return litemallDistributionLogMapper.selectByExample(example);
    }

    public List<LitemallDistributionLog> findByDate(LocalDate date) {
        LitemallDistributionLogExample example = new LitemallDistributionLogExample();
        LitemallDistributionLogExample.Criteria criteria = example.createCriteria();
        criteria.andDeletedEqualTo(false).andInviteDateEqualTo(date);

        return litemallDistributionLogMapper.selectByExample(example);

    }
}
